<?php

namespace Modules\SmallApi\Http\Controllers;


use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\SmallApi\Service\RepairstoreGoodsService;
use HiCommon\Service\OrderPayService;

class RepairstoreController extends BaseController
{

    /**
     *    车辆检修列表
     *    yang 2019 09 05
     **/
    public function get_goods_list(Request $request)
    {
        $data = $request->all();

        $arr_list = RepairstoreGoodsService::get_list($data);
        return response_json($arr_list);
    }


    /**
     *    获取指定商品详情
     *    yang 2019 09 05
     **/
    public function get_goods_detail(Request $request)
    {
        $nId = $request->get('id');
        $arr_list = RepairstoreGoodsService::get_one((int)$nId);
        return response_json($arr_list);
    }


    /**
     *    获取维修种类
     */
    public function get_repairstore_type()
    {
        $arr_list = RepairstoreGoodsService::get_repairstore_type();

        return response_json($arr_list);
    }

    /**
     *    立即购买生成订单
     *    yang 2019 09 07
     **/
    public function buy_goods_now(Request $request)
    {
        $data = $request->all();

        //开启事务
        shiwu_start();
        $res = RepairstoreGoodsService::buy_goods_now($data);
        shiwu_end($res);
        return response_json($res);
    }

    /**
     * 支付订单
     *
     */
    public function repair_pay_order(Request $request)
    {
        /*$res = OrderPayService::notify_wechat_for_order_repairstore('OR19100802570022212',1);
        dd($res);*/

        $data = $request->all();

        $res = RepairstoreGoodsService::repair_pay_order($data);

        return response_json($res);
    }

    /**
     * 维修店商品订单（用户修改订单状态）
     */
    public function repairOrderModifyState(Request $request)
    {
        $data = $request->all();

        $result = RepairstoreGoodsService::repairOrderModifyState($data);

        return $result;
    }

    /**
     *  获取维修店的订单详情
     *  hinq 2019 09 23
     *
     **/
    public function get_repairstore_goods_detail_to_order(Request $request)
    {
        $nId = $request->get('id');
        $arr_list = RepairstoreGoodsService::get_repairstore_goods_detail_to_order((int)$nId);
        return response_json($arr_list);
    }

    /**
     *  用户获取服务订单列表
     *
     **/
    public function getUserOrderList(Request $request)
    {
        $data = $request->all();

        $arr_list = RepairstoreGoodsService::getUserOrderList($data);

        return response_json($arr_list);
    }



    /**
     *  用户评论订单(维修店服务商品订单评论)
     *  hinq 2019 09 27
     *  
     **/
    public function create_order_repairstore_comment( Request $request ){
        try {
        $arr_input = (array) $request->all();
        shiwu_start();
        $res = RepairstoreGoodsService::create_order_repairstore_comment( (array) $arr_input );
        shiwu_end($res);
        return response_json($res);
        } catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }




}